﻿using psafth.RCTiming.Main.Pages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace psafth.RCTiming.Main.Controls
{
    /// <summary>
    /// Interaction logic for RacePageSelectedDriver.xaml
    /// </summary>
    public partial class RacePageSelectedDriver : UserControl
    {
        private HeatCompetitor _competitor
        {
            get;
            set;
        }

        public RacePageSelectedDriver()
        {
            InitializeComponent();
        }

        public void SetInformation(HeatCompetitor competitor)
        {
            try
            {
                lblDriverFullName.Text = string.Empty;
                lblClubFullName.Text = string.Empty;
                lblTransponderId.Text = string.Empty;

                if (competitor != null)
                {
                    _competitor = competitor;

                    if (_competitor.FullName != null)
                    {
                        lblDriverFullName.Text = _competitor.FullName;
                        lblClubFullName.Text = _competitor.ClubName;
                    }
                    else
                    {
                        lblDriverFullName.Text = "Okänd";
                    }

                    if (_competitor.TransponderId > 0)
                        lblTransponderId.Text = _competitor.TransponderId.ToString();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        private Window ParentWindow
        {
            get
            {
                return Window.GetWindow(this);
            }
        }

        private void btnCorrectionAdd_Click(object sender, RoutedEventArgs e)
        {
            MainWindow t = ParentWindow as MainWindow;

            if (_competitor.TransponderId > 0)
                t.ManualCount(_competitor.TransponderId, false, false);
            else if (!string.IsNullOrWhiteSpace(_competitor.LicenceNumber))
                t.ManualCount(_competitor.LicenceNumber, false, false);
        }

        private void btnCorrectionRemove_Click(object sender, RoutedEventArgs e)
        {
            MainWindow t = ParentWindow as MainWindow;

            if (_competitor.TransponderId > 0)
                t.ManualCount(_competitor.TransponderId, true, false);
            else if (!string.IsNullOrWhiteSpace(_competitor.LicenceNumber))
                t.ManualCount(_competitor.LicenceNumber, true, false);
        }

        private void btnCorrectionPenalty_Click(object sender, RoutedEventArgs e)
        {
            MainWindow t = ParentWindow as MainWindow;

            if (_competitor.TransponderId > 0)
                t.ManualCount(_competitor.TransponderId, true, true);
            else if (!string.IsNullOrWhiteSpace(_competitor.LicenceNumber))
                t.ManualCount(_competitor.LicenceNumber, true, true);
        }

        private void btnDisqualify_Click(object sender, RoutedEventArgs e)
        {

        }

    }
}
